package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.DepDao;
import com.pojo.Dep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DepService  extends ServiceImpl<DepDao, Dep> {

    @Autowired
    private DepDao depDao;

    public int addDep(Dep dep){
        return depDao.insert(dep);
    }

    public IPage searchDep(int page, int limit, Integer depId, String depName){
        Page search=new Page(page,limit);

        QueryWrapper q=new QueryWrapper();
        if (depId!=null){
            q.eq("depId",depId);
        }
        if (depName!=null&&depName.length()>0){
            q.eq("depName","%"+depName+"%");
        }
        IPage result=depDao.selectPage(search,q);
        return result;

    }

    public Dep findById(Integer depId){
        return depDao.selectById(depId);
    }



}

